home *** CD-ROM | disk | FTP | other *** search
- /* *****************************************************************************
- *
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- *
- ***************************************************************************** */
- #include <gl.h>
- #include <device.h>
- #include <math.h>
- #include "fast.h"
- #include "event.h"
- #include "fft.h"
-
- void display();
- void InitFast();
- void matgen();
- void dir_fft(), inv_fft();
- double second();
-
-
- extern int mainmenu, realmenu, fouriermenu, fourier2menu, quitmenu;
-
- int do_exit;
- int ask_quit;
-
- int x_size, y_size;
- int this_proc;
-
- float *mat, *save, *power;
- int * mycolors;
- int *ipvt, lda, info, x_0, y_0;
-
- double this_time, this_flop;
-
- char title[128];
-
-
- fast (progname)
- char *progname;
- {
- InitFast();
- Init(progname);
-
- do_exit = FALSE;
-
- while(! do_exit) {
- event();
- }
- }
-
- do_frame(){
-
- char str[32];
- float v[2];
-
- viewport(0,WIN_SIZE+WIN_RIGHT,0,WIN_SIZE);
-
- cpack (oBLACK);
- clear ();
-
- cpack (oGREEN);
- ortho2(0,WIN_SIZE+WIN_RIGHT,0, WIN_SIZE);
-
- sprintf( str, "SIZE = %d x %d", x_size, y_size);
- cmov2i( 250, WIN_SIZE - 30);
- charstr(str);
-
- cmov2i( 100, 20);
- charstr(title);
-
- bgnpolygon();
- v[0] = WIN_SIZE;
- v[1] = WIN_SIZE/2;
- cpack(oBLACK);
- v2f(v);
- v[1] -= 100;
- cpack(0x007fff);
- v2f(v);
- v[0] += 50;
- v2f(v);
- v[1] += 100;
- cpack(oBLACK);
- v2f(v);
- endpolygon();
- v[1] -= 100;
- bgnpolygon();
- cpack(0x007fff);
- v2f(v);
- v[1] -= 100;
- cpack(0x00ffff);
- v2f(v);
- v[0] -= 50;
- v2f(v);
- v[1] += 100;
- cpack(0x007fff);
- v2f(v);
- endpolygon();
-
- bgnpolygon();
- v[0] = WIN_SIZE;
- v[1] = WIN_SIZE/2;
- cpack(oBLACK);
- v2f(v);
- v[1] += 100;
- cpack(0xff7f00);
- v2f(v);
- v[0] += 50;
- v2f(v);
- cpack(0xff7f00);
- v2f(v);
- v[1] -= 100;
- cpack(oBLACK);
- v2f(v);
- endpolygon();
- v[1] += 100;
- bgnpolygon();
- cpack(0xff7f00);
- v2f(v);
- v[1] += 100;
- cpack(oCYAN);
- v2f(v);
- v[0] -= 50;
- v2f(v);
- v[1] -= 100;
- cpack(0xff7f00);
- v2f(v);
- endpolygon();
- cpack(oWHITE);
- rect(WIN_SIZE,WIN_SIZE/2-200,WIN_SIZE+50,WIN_SIZE/2+200);
-
- cmov2i( WIN_SIZE+55, WIN_SIZE/2 - 200 -4);
- charstr(" -Max");
-
- cmov2i( WIN_SIZE+55, WIN_SIZE/2 + 200 -4);
- charstr(" +Max");
-
- cmov2i( WIN_SIZE+55, WIN_SIZE/2 -4);
- charstr(" 0.0 ");
-
- }
- ShowFast()
- {
- x_0 = (WIN_SIZE/2)-(x_size/2);
- y_0 = (WIN_SIZE/2)-(y_size/2);
- do_frame();
- viewport( x_0, x_0 + x_size + 2, y_0, y_0 + y_size + 2);
- ortho2(-1, x_size+1,-1, y_size+1);
- DrawFast();
- }
-
- void do_quit()
- {
- if(mat)
- free(mat);
- gexit();
- exit(0);
- }
-
-
- void do_rightmouse()
- {
- ask_quit = 0;
-
- dopup(mainmenu);
-
- if(ask_quit)
- dopup(quitmenu);
-
- }
-
- void display()
- {
- do_frame();
- swapbuffers();
- ShowFast();
- swapbuffers();
- }
-
- void do_resize(){
-
- lda = y_size + 1;
-
- if( mat){
- mat = (float *)realloc( mat, lda * x_size * sizeof(float));
- power = (float *)realloc( power, lda * x_size * sizeof(float));
- mycolors = (int *)realloc( mycolors, lda * x_size * sizeof(int));
- save = (float *)realloc( save, (y_size + 3*x_size + 4 * FACTOR_SPACE) * sizeof(float));
- }
- else{
- mat = (float *)malloc( lda * x_size * sizeof(float));
- power = (float *)malloc( lda * x_size * sizeof(float));
- mycolors = (int *)malloc( lda * x_size * sizeof(int));
- save = (float *)malloc( (y_size + 3*x_size + 4 * FACTOR_SPACE) * sizeof(float));
- }
-
- sfft2di( y_size, x_size, save);
- matgen();
- matcolor_(&y_size, &x_size, mat, mycolors, &lda);
- mainmenu = realmenu;
- strcpy( title, "XY domain");
- display();
- }
- void add_noise() {
-
- matnoise_( mat, &lda, &y_size, &x_size);
- matcolor_(&y_size, &x_size, mat, mycolors, &lda);
- sprintf(title,(mainmenu == realmenu) ? "XY domain" : "FOURIER domain");
- display();
- }
-
- void this_pow(){
- matpower_(&y_size, &x_size, mat, power, &lda);
- matlog_(&y_size, &x_size, power, &lda);
- matcolor_(&y_size, &x_size, power, mycolors, &lda);
- sprintf(title,"Power Spectrum (Log Scale)");
- display();
- }
-
- void size500_500(){
-
- x_size = 500;
- y_size = 500;
- do_resize();
- }
-
- void size512_512(){
-
- x_size = 512;
- y_size = 512;
- do_resize();
- }
-
- void size576_405(){
-
- x_size = 576;
- y_size = 405;
- do_resize();
- }
-
- void dir_fft(){
-
- this_time = second();
- sfft2d( -1, y_size, x_size, mat, lda, save);
- this_time = second() - this_time;
- matcolor_(&y_size, &x_size, mat, mycolors, &lda);
- mainmenu = fouriermenu;
- sprintf(title,"Direct (%d x %d) FFT performed in %.2f Seconds \n",
- y_size,x_size, this_time);
- display();
- }
- void inv_fft(){
- float alpha = 1./(float)(x_size*y_size);
-
- this_time = second();
- sfft2d( 1, y_size, x_size, mat, lda, save);
- sscal2d_( &y_size, &x_size, &alpha, mat, &lda);
- this_time = second() - this_time;
- matcolor_(&y_size, &x_size, mat, mycolors, &lda);
- mainmenu = realmenu;
- sprintf(title,"Inverse (%d x %d) FFT performed in %.2f Seconds \n",
- y_size,x_size, this_time);
- display();
- }
-
- void this_quit(){
-
- ask_quit = 1;
- }
- void InitFast(){
-
- this_proc = mp_numthreads_();
- x_size = 512;
- y_size = 512;
- }
- #define SCALE 20
- #define XLENGTH 19*SCALE
- #define YLENGTH 11*SCALE
-
- void myrec( float *pt, int xl, int yl, double val){
- int i, j;
- for( j = 0 ; j < xl; j++, pt += lda)
- for( i = 0; i < yl ; i++)
- pt[i] += val;
- }
- myF( float *pt, double val){
- myrec( pt, SCALE, 7*SCALE, val);
- myrec( pt+SCALE*lda+3*SCALE, 2*SCALE, SCALE, val);
- myrec( pt+SCALE*lda+6*SCALE, 3*SCALE, SCALE, val);
- }
- myT( float *pt, double val){
- myrec( pt+0*SCALE*lda+6*SCALE, 5*SCALE, 1*SCALE, val);
- myrec( pt+2*SCALE*lda+0*SCALE, 1*SCALE, 6*SCALE, val);
- }
- void mywrite( float *pt){
- myrec( pt, XLENGTH, YLENGTH, 1.);
- myF( pt + 2 * SCALE + 2 * SCALE*lda, -2.);
- myF( pt + 2 * SCALE + 7 * SCALE*lda, -2.);
- myT( pt + 2 * SCALE + 12 * SCALE*lda, -2.);
- }
-
- void matgen(){
- bzero( mat, lda * x_size * sizeof(float));
- }
- void add_box(){
- int xor, yor;
- xor = x_size/2 - XLENGTH/2;
- yor = y_size/2 - YLENGTH/2;
- mywrite( mat+yor+xor*lda);
- matcolor_(&y_size, &x_size, mat, mycolors, &lda);
- display();
- }
-